package com.atguigu.ggkt.vod.service.impl;

import com.atguigu.ggkt.model.vod.VideoVisitor;
import com.atguigu.ggkt.vo.vod.VideoVisitorCountVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.ggkt.vod.service.VideoVisitorService;
import com.atguigu.ggkt.vod.mapper.VideoVisitorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author 欣欣
* @description 针对表【video_visitor(视频来访者记录表)】的数据库操作Service实现
* @createDate 2022-09-25 10:29:42
*/
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor>
    implements VideoVisitorService{
    @Autowired
    private VideoVisitorMapper videoVisitorMapper;

    /**
     * 根据进入时间统计课程人数
     * @param courseId
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public Map<String, Object> findCount(Long courseId, String startDate, String endDate) {
        List<VideoVisitorCountVo> countVoList= videoVisitorMapper.findCountByCon(courseId,startDate,endDate);
        List<Integer> userCountList =
                countVoList.stream().map(VideoVisitorCountVo::getUserCount).collect(Collectors.toList());
        List<String> joinTimeList =
                countVoList.stream().map(VideoVisitorCountVo::getJoinTime).collect(Collectors.toList());
        Map<String,Object> map = new HashMap<>();
        map.put("xDate",joinTimeList);
        map.put("yDate",userCountList);
        return map;
    }
}




